﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FDEEDrawingModels
{
    public class PlotCrossBeamTable
    {
        public static void DrawingCapBeamTable(Database db, MemberBase ret, EStructure eType, string dwgPath,
          string typeName, string pierName, string capLength, ref System.Data.DataTable dt, ref Dictionary<string, System.Data.DataTable> dicP, int scale = 1,string title= "MAINLINE")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("表格数据为空");
            }

            #region 测试数据
            #endregion

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin;
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            BPTMBase res = ret as BPTMBase;
            List<TendonCollection> divDic = new List<TendonCollection>();
            divDic.Add(res.TendonList);
            #endregion
            bool isLeft = false;
            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
               
                ext = ext = new Extents2d(Point2d.Origin.Convert2D(420 * i), Point2d.Origin);
                lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                    Extensions.curFont, scale, divDic[i], pierName, ref dt,ref dicP, i, title, isLeft);
                Common.CreateLayout(db, "预应力数据表" + i, ext, scale, 1);

            }
            #endregion

            #region 创建布局、视口

            #endregion
        }
        public static void DrawingCapBeamTable(Database db, List<MemberBase> rets, EStructure eType, string dwgPath,
        string typeName, ref System.Data.DataTable dt, ref Dictionary<string, System.Data.DataTable> dicP, ref int pagecount, int scale = 1, string title = "MAINLINE",string tkPath="")
        {
            bool isLeft = false;
            if (typeName == "BPTM2U")
                isLeft = true;
            BPTMBase res = rets[0] as BPTMBase;
            if (res.TendonList.Count > 15)
            {
                int pageNo = rets.Count;
                //if (rets.Count / 2.0 > pageNo)
                //    pageNo += 1;
                Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
                Extents2d ext1 = new Extents2d(Point2d.Origin, Point2d.Origin);
                Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
                Point2d M1 = CT;
                int num = 0;
                Dictionary<int, List<Extents2d>> dic = new Dictionary<int, List<Extents2d>>();
                List<Extents2d> lst = new List<Extents2d>();
                int all = pageNo+1;
                for (int n = 0; n < all; n++)
                {
                    //if (n % 2 == 0)
                    //    num++;

                    M1 = CT.Convert2D(420 * n);
                    if (n < rets.Count)
                    {
                        MemberBase ret = rets[n];
                        if (ret == null)
                        {
                            throw new Exception("表格数据为空");
                        }



                        #region 分页处理
                        res = ret as BPTMBase;
                        List<TendonCollection> divDic = new List<TendonCollection>();
                        divDic.Add(res.TendonList);
                        #endregion
                        #region 绘制表格
                        Table lasTb = new Table();


                        //if (rets.Count > 1)
                        //{
                        //    if (rets.Count % 2 == 0)
                        //    {
                        //        if (n % 2 == 0)
                        //        {
                        //            ext = new Extents2d(M1, M1);
                        //            lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                        //                Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0);
                        //        }
                        //        else
                        //        {
                        //            ext1 = new Extents2d(M1, M1);
                        //            lasTb = DrawBeamTable(db, ref ext1, M1.Convert3D(),
                        //           Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0);
                        //            if (n > 0)
                        //            {
                        //                lst = new List<Extents2d>();
                        //                lst.Add(ext);
                        //                lst.Add(ext1);
                        //                dic.Add(num, lst);
                        //                //Common.CreateLayout(db, "预应力数据表" + num, ext, ext1, scale, 1);
                        //            }
                        //        }
                        //    }
                        //    else
                        //    {
                        //        if (n % 2 == 0)
                        //        {
                        //            ext = new Extents2d(M1, M1);
                        //            lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                        //                Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0);
                        //            if (n == rets.Count - 1)
                        //            {
                        //                lst = new List<Extents2d>();
                        //                lst.Add(ext);
                        //                //lst.Add(ext1);
                        //                dic.Add(num, lst);
                        //                //Common.CreateLayout(db, "预应力数据表" + num, ext, scale, 1);
                        //            }
                        //        }
                        //        else
                        //        {
                        //            ext1 = new Extents2d(M1, M1);
                        //            lasTb = DrawBeamTable(db, ref ext1, M1.Convert3D(),
                        //           Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0);
                        //            if (n > 0)
                        //            {
                        //                lst = new List<Extents2d>();
                        //                lst.Add(ext);
                        //                lst.Add(ext1);
                        //                dic.Add(num, lst);
                        //                //Common.CreateLayout(db, "预应力数据表" + num, ext, ext1, scale, 1);
                        //            }
                        //        }
                        //    }
                        //}
                        //else
                        //{
                            num++;
                            ext = new Extents2d(M1, M1);
                            lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                   Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0,title, isLeft);
                            //Common.CreateLayout(db, "预应力数据表", ext, ext1, scale, 1);
                            lst = new List<Extents2d>();
                            lst.Add(ext);
                        //dic.Add(num, lst);
                        //lst.Add(ext1);
                        dic.Add(num, lst);
                        //}
                        #endregion
                    }
                    else
                    {
                        Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
                        Dictionary<string, string> dicT = new Dictionary<string, string>();

                        dicT = new Dictionary<string, string>();
                        MemberBase re = rets[rets.Count - 1];
                        BPTMBase ptm = re as BPTMBase;
                        dicT.Add("OVM.P15-" + ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum.ToString(), "string");
                        dicA.Add("TYPE1", dicT);
                        string _blcName = "TBPlinth";
                        if(ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum<=19)
                            _blcName = "TBPlinth19";
                        db.CopyBlockFromFile(dwgPath, _blcName);
                        ext = new Extents2d(M1, M1);
                        BlockTool.InsertBlockReference(M1.Convert3D(), 1, _blcName, dwgPath, dicA, null, ref ext);

                        double tbW = ext.W();

                        Point3d ptNote = M1.Convert3D(tbW + 25, -10);
                        string content = "Notes:\\P"
    + "1.All dimensions are in m unless otherwise indicated.\\P"
    + "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer &architect before\\P commencement of work."
    + "3.All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P"
    + "4.All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P"
    + "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P"
    + "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P"
    + "7.Concrete cover shall be 0.050m for cross beam.\\P"
    + "8.In case there is any constrain at the left end such as difficulty to access,\\P"
    + "tensioning can be performed by jacking from right end at the option of the contractor.\\P"
    + "9.The void space between the duct and the tendon shall be filled with grout.\\P"
    + "10.The scaffolding supported cross beam should be removed before stressing stage 1 only when concrete strength of cross\\P beam has reached or exceed 36MPa(cylinder).";

                        TextPloter.PrintMultiText(db, ref ext, ptNote, content, 1, 3, 210);

                        if (dic.Keys.Contains(num))
                        {
                            lst.Add(ext);
                            dic.Remove(num);
                        }
                        else
                        {
                            lst = new List<Extents2d>();
                            lst.Add(ext);
                        }
                        dic.Add(num, lst);
                    }
                }

                if (dic.Count > 0)
                {
                    Common.CreateLayout(db, "预应力数据表", dic, 1,false, tkPath);
                }
                pagecount = dic.Count;
            }
            else
            {
                int pageNo = rets.Count / 2;
                if (rets.Count / 2.0 > pageNo)
                    pageNo += 1;
                Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
                Extents2d ext1 = new Extents2d(Point2d.Origin, Point2d.Origin);
                Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale);
                Point2d M1 = CT;
                int num = 0;
                Dictionary<int, List<Extents2d>> dic = new Dictionary<int, List<Extents2d>>();
                List<Extents2d> lst = new List<Extents2d>();
                int all = rets.Count + 1;
                for (int n = 0; n < all; n++)
                {
                    if (n % 2 == 0)
                        num++;

                    M1 = CT.Convert2D(420 * n);
                    if (n < rets.Count)
                    {
                        MemberBase ret = rets[n];
                        if (ret == null)
                        {
                            throw new Exception("表格数据为空");
                        }



                        #region 分页处理
                        res = ret as BPTMBase;
                        List<TendonCollection> divDic = new List<TendonCollection>();
                        divDic.Add(res.TendonList);
                        #endregion
                        #region 绘制表格
                        Table lasTb = new Table();


                        if (rets.Count > 1)
                        {
                            if (rets.Count % 2 == 0)
                            {
                                if (n % 2 == 0)
                                {
                                    ext = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                        Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                }
                                else
                                {
                                    ext1 = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext1, M1.Convert3D(),
                                   Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                    if (n > 0)
                                    {
                                        lst = new List<Extents2d>();
                                        lst.Add(ext);
                                        lst.Add(ext1);
                                        dic.Add(num, lst);
                                        //Common.CreateLayout(db, "预应力数据表" + num, ext, ext1, scale, 1);
                                    }
                                }
                            }
                            else
                            {
                                if (n % 2 == 0)
                                {
                                    ext = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                        Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                    if (n == rets.Count - 1)
                                    {
                                        lst = new List<Extents2d>();
                                        lst.Add(ext);
                                        //lst.Add(ext1);
                                        dic.Add(num, lst);
                                        //Common.CreateLayout(db, "预应力数据表" + num, ext, scale, 1);
                                    }
                                }
                                else
                                {
                                    ext1 = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext1, M1.Convert3D(),
                                   Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                    if (n > 0)
                                    {
                                        lst = new List<Extents2d>();
                                        lst.Add(ext);
                                        lst.Add(ext1);
                                        dic.Add(num, lst);
                                        //Common.CreateLayout(db, "预应力数据表" + num, ext, ext1, scale, 1);
                                    }
                                }
                            }
                        }
                        else
                        {
                            ext = new Extents2d(M1, M1);
                            lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                   Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                            //Common.CreateLayout(db, "预应力数据表", ext, ext1, scale, 1);
                            lst = new List<Extents2d>();
                            lst.Add(ext);
                            //lst.Add(ext1);
                            dic.Add(num, lst);
                        }
                        #endregion
                    }
                    else
                    {
                        Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
                        Dictionary<string, string> dicT = new Dictionary<string, string>();

                        dicT = new Dictionary<string, string>();
                        MemberBase re = rets[rets.Count - 1];
                        BPTMBase ptm = re as BPTMBase;
                        dicT.Add("OVM.P15-" + ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum.ToString(), "string");
                        dicA.Add("TYPE1", dicT);
                        string _blcName = "TBPlinth";
                        if (ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum <= 19)
                            _blcName = "TBPlinth19";
                        db.CopyBlockFromFile(dwgPath, _blcName);
                        ext = new Extents2d(M1, M1);
                        BlockTool.InsertBlockReference(M1.Convert3D(), 1, _blcName, dwgPath, dicA, null, ref ext);

                        double tbW = ext.W();

                        Point3d ptNote = M1.Convert3D(tbW + 25, -10);
                        string content = "Notes:\\P"
    + "1.All dimensions are in m unless otherwise indicated.\\P"
    + "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer &architect before\\P commencement of work."
    + "3.All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P"
    + "4.All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P"
    + "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P"
    + "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P"
    + "7.Concrete cover shall be 0.050m for cross beam.\\P"
    + "8.In case there is any constrain at the left end such as difficulty to access,\\P"
    + "tensioning can be performed by jacking from right end at the option of the contractor.\\P"
    + "9.The void space between the duct and the tendon shall be filled with grout.\\P"
    + "10.The scaffolding supported cross beam should be removed before stressing stage 1 only when concrete strength of cross\\P beam has reached or exceed 36MPa(cylinder).";

                        TextPloter.PrintMultiText(db, ref ext, ptNote, content, 1, 3, 210);

                        if (dic.Keys.Contains(num))
                        {
                            lst.Add(ext);
                            dic.Remove(num);
                        }
                        else
                        {
                            lst = new List<Extents2d>();
                            lst.Add(ext);
                        }
                        dic.Add(num, lst);
                    }
                }

                if (dic.Count > 0)
                {
                    Common.CreateLayout(db, "预应力数据表", dic, 1,false, tkPath);
                }
                pagecount = dic.Count;
            }
        }

        public static void DrawingCapBeamTableNew(Database db, List<MemberBase> rets, EStructure eType, string dwgPath,
   string typeName, ref System.Data.DataTable dt, ref Dictionary<string, System.Data.DataTable> dicP, ref int pagecount, int scale = 1, string title = "MAINLINE", string tkPath = "")
        {
            bool isLeft = false;
            if (typeName == "BPTM2U")
                isLeft = true;
            BPTMBase res = rets[0] as BPTMBase;
            if (res.TendonList.Count > 15)
            {
                int pageNo = rets.Count;
            
                Extents2d ext = new Extents2d(Point2d.Origin.Convert2D(0,297), Point2d.Origin.Convert2D(0, 297));
                Extents2d ext1 = new Extents2d(Point2d.Origin.Convert2D(0, 297), Point2d.Origin.Convert2D(0, 297));
                Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale).Convert2D(0, 297);
                Point2d M1 = CT;
                int num = 0;
                Dictionary<int, List<Extents2d>> dic = new Dictionary<int, List<Extents2d>>();
                List<Extents2d> lst = new List<Extents2d>();
                int all = pageNo + 1;
                for (int n = 0; n < all; n++)
                {
                 
                    M1 = CT.Convert2D(420 * n);
                    if (n < rets.Count)
                    {
                        MemberBase ret = rets[n];
                        if (ret == null)
                        {
                            throw new Exception("表格数据为空");
                        }



                        #region 分页处理
                        res = ret as BPTMBase;
                        List<TendonCollection> divDic = new List<TendonCollection>();
                        divDic.Add(res.TendonList);
                        #endregion
                        #region 绘制表格
                        Table lasTb = new Table();
                        
                        num++;
                        ext = new Extents2d(M1, M1);
                        lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                               Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                     
                        lst = new List<Extents2d>();
                        lst.Add(ext);                     
                        dic.Add(num, lst);
                    
                        #endregion
                    }
                    else
                    {
                        Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
                        Dictionary<string, string> dicT = new Dictionary<string, string>();

                        dicT = new Dictionary<string, string>();
                        MemberBase re = rets[rets.Count - 1];
                        BPTMBase ptm = re as BPTMBase;
                        dicT.Add("OVM.P15-" + ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum.ToString(), "string");
                        dicA.Add("TYPE1", dicT);
                        string _blcName = "TBPlinth";
                        if (ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum <= 19)
                            _blcName = "TBPlinth19";
                        db.CopyBlockFromFile(dwgPath, _blcName);
                        ext = new Extents2d(M1, M1);
                        BlockTool.InsertBlockReference(M1.Convert3D(), 1, _blcName, dwgPath, dicA, null, ref ext);

                        double tbW = ext.W();

                        Point3d ptNote = M1.Convert3D(tbW + 25, -5);
                        string content = "Notes:\\P"
    + "1.All dimensions are in m unless otherwise indicated.\\P"
    + "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer &architect before\\P commencement of work."
    + "3.All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P"
    + "4.All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P"
    + "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P"
    + "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P"
    + "7.Concrete cover shall be 0.050m for cross beam.\\P"
    + "8.In case there is any constrain at the left end such as difficulty to access,\\P"
    + "tensioning can be performed by jacking from right end at the option of the contractor.\\P"
    + "9.The void space between the duct and the tendon shall be filled with grout.\\P"
    + "10.The scaffolding supported cross beam should be removed before stressing stage 1 only when concrete strength of cross\\P beam has reached or exceed 36MPa(cylinder).";

                        TextPloter.PrintMultiText(db, ref ext, ptNote, content, 1, 3, 210);

                        if (dic.Keys.Contains(num))
                        {
                            lst.Add(ext);
                            dic.Remove(num);
                        }
                        else
                        {
                            lst = new List<Extents2d>();
                            lst.Add(ext);
                        }
                        dic.Add(num, lst);
                    }
                }

                if (dic.Count > 0)
                {
                    //Common.CreateLayout(db, "盖梁钢筋数据表", dic, 1, false, tkPath);
                    Common.CreateLayoutNew(db, "盖梁钢筋数据表", dic, 1, -1, false, tkPath);
                }
                pagecount = dic.Count;
            }
            else
            {
                int pageNo = rets.Count / 2;
                if (rets.Count / 2.0 > pageNo)
                    pageNo += 1;
                Extents2d ext = new Extents2d(Point2d.Origin.Convert2D(0, 297), Point2d.Origin.Convert2D(0, 297));
                Extents2d ext1 = new Extents2d(Point2d.Origin.Convert2D(0, 297), Point2d.Origin.Convert2D(0, 297));
                Point2d CT = Point2d.Origin.Convert2D(0, -2 * scale).Convert2D(0, 297);
                Point2d M1 = CT;
                int num = 0;
                Dictionary<int, List<Extents2d>> dic = new Dictionary<int, List<Extents2d>>();
                List<Extents2d> lst = new List<Extents2d>();
                int all = rets.Count + 1;
                for (int n = 0; n < all; n++)
                {
                    if (n % 2 == 0)
                        num++;

                    M1 = CT.Convert2D(420 * n);
                    if (n < rets.Count)
                    {
                        MemberBase ret = rets[n];
                        if (ret == null)
                        {
                            throw new Exception("表格数据为空");
                        }



                        #region 分页处理
                        res = ret as BPTMBase;
                        List<TendonCollection> divDic = new List<TendonCollection>();
                        divDic.Add(res.TendonList);
                        #endregion
                        #region 绘制表格
                        Table lasTb = new Table();


                        if (rets.Count > 1)
                        {
                            if (rets.Count % 2 == 0)
                            {
                                if (n % 2 == 0)
                                {
                                    ext = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                        Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                }
                                else
                                {
                                    ext1 = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext1, M1.Convert3D(),
                                   Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                    if (n > 0)
                                    {
                                        lst = new List<Extents2d>();
                                        lst.Add(ext);
                                        lst.Add(ext1);
                                        dic.Add(num, lst);
                                        //Common.CreateLayout(db, "预应力数据表" + num, ext, ext1, scale, 1);
                                    }
                                }
                            }
                            else
                            {
                                if (n % 2 == 0)
                                {
                                    ext = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                        Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                    if (n == rets.Count - 1)
                                    {
                                        lst = new List<Extents2d>();
                                        lst.Add(ext);
                                        //lst.Add(ext1);
                                        dic.Add(num, lst);
                                        //Common.CreateLayout(db, "预应力数据表" + num, ext, scale, 1);
                                    }
                                }
                                else
                                {
                                    ext1 = new Extents2d(M1, M1);
                                    lasTb = DrawBeamTable(db, ref ext1, M1.Convert3D(),
                                   Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                    if (n > 0)
                                    {
                                        lst = new List<Extents2d>();
                                        lst.Add(ext);
                                        lst.Add(ext1);
                                        dic.Add(num, lst);
                                        //Common.CreateLayout(db, "预应力数据表" + num, ext, ext1, scale, 1);
                                    }
                                }
                            }
                        }
                        else
                        {
                            ext = new Extents2d(M1, M1);
                            if (res.TendonList.Count > 0)
                            {
                                lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(),
                                       Extensions.curFont, scale, res.TendonList, ret.PierNumber, ref dt, ref dicP, 0, title, isLeft);
                                //Common.CreateLayout(db, "预应力数据表", ext, ext1, scale, 1);
                                lst = new List<Extents2d>();
                                lst.Add(ext);
                                //lst.Add(ext1);
                                dic.Add(num, lst);
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
                        Dictionary<string, string> dicT = new Dictionary<string, string>();

                        dicT = new Dictionary<string, string>();
                        MemberBase re = rets[rets.Count - 1];
                        BPTMBase ptm = re as BPTMBase;
                        dicT.Add("OVM.P15-" + ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum.ToString(), "string");
                        dicA.Add("TYPE1", dicT);
                        string _blcName = "TBPlinth";
                        if (ptm.TendonList[ptm.TendonList.Count - 1].StrandsNum <= 19)
                            _blcName = "TBPlinth19";
                        db.CopyBlockFromFile(dwgPath, _blcName);
                        ext = new Extents2d(M1, M1);
                        BlockTool.InsertBlockReference(M1.Convert3D(), 1, _blcName, dwgPath, dicA, null, ref ext);

                        double tbW = ext.W();

                        Point3d ptNote = M1.Convert3D(tbW + 25, -5);
                        string content = "Notes:\\P"
    + "1.All dimensions are in m unless otherwise indicated.\\P"
    + "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer &architect before\\P commencement of work."
    + "3.All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P"
    + "4.All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P"
    + "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P"
    + "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P"
    + "7.Concrete cover shall be 0.050m for cross beam.\\P"
    + "8.In case there is any constrain at the left end such as difficulty to access,\\P"
    + "tensioning can be performed by jacking from right end at the option of the contractor.\\P"
    + "9.The void space between the duct and the tendon shall be filled with grout.\\P"
    + "10.The scaffolding supported cross beam should be removed before stressing stage 1 only when concrete strength of cross\\P beam has reached or exceed 36MPa(cylinder).";

                        TextPloter.PrintMultiText(db, ref ext, ptNote, content, 1, 3, 210);

                        if (dic.Keys.Contains(num))
                        {
                            lst.Add(ext);
                            dic.Remove(num);
                        }
                        else
                        {
                            lst = new List<Extents2d>();
                            lst.Add(ext);
                        }
                        dic.Add(num, lst);
                    }
                }

                if (dic.Count > 0)
                {
                    //Common.CreateLayout(db, "盖梁钢筋数据表", dic, 1, false, tkPath);
                    Common.CreateLayoutNew(db, "盖梁钢筋数据表", dic, 1,-1, false, tkPath);
                 
                }
                pagecount = dic.Count;
            }
        }

        public static void DrawingCapBeamRebarNew(Database db, string dwgPath, double length,
string typeName, double scale = 1, string tkPath = "", string columnNo = "")
        {
            try
            {
                string _dwgPath = dwgPath;
                string _blcName = "";
                string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
                string reberBlockPath = directoryName + @"\BeamReberBlock.dwg";//构造物
                #region 插入钢筋
                List<Extents2d> exts = new List<Extents2d>();

                if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2" || typeName == "BPTM2S" || typeName == "BPTM3S")
                    DrawingMainCapBeamRebar(db, Point3d.Origin.Convert3D(420 * 0.45, 297 * 2), length, typeName, _dwgPath, scale, ref exts, columnNo);
                else
                    DrawingMainCapBeamRebar(db, Point3d.Origin.Convert3D(420 * 0.45, 297*2), length, typeName, _dwgPath, scale, ref exts, columnNo);

                if (exts.Count > 0)
                {
                    for (int i = 0; i < exts.Count; i++)
                    {

                        if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2" || typeName == "BPTM2S" || typeName == "BPTM3S")
                        {
                            if (i < exts.Count - 1)
                                Common.CreateRLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -2, i, false, tkPath);
                            else
                                Common.CreateBeamPLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -2, i, false, tkPath);

                            _blcName = "R" + typeName.Replace("B", "");
                            db.CopyBlockFromFile(reberBlockPath, _blcName);

                            if (typeName == "BPTM3S")
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -2).Convert3D(355.26, 238.6), 1, _blcName, reberBlockPath, 0, false);
                            else if (typeName == "BPTE3")
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -2).Convert3D(355.26, 249.1), 1, _blcName, reberBlockPath, 0, false);
                            else
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -2).Convert3D(355.26, 244), 1, _blcName, reberBlockPath, 0, false);
                        }
                        else
                        {
                            if (i < exts.Count - 1)
                                Common.CreateRLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -2, i, false, tkPath);
                            else
                                Common.CreateBeamPLayoutNew(db, "盖梁钢筋数据表", exts[i], 1, 1, -2, i, false, tkPath);

                            _blcName = "R" + typeName.Replace("B", "");
                            db.CopyBlockFromFile(reberBlockPath, _blcName);

                            if (typeName == "BPTM3S")
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -2).Convert3D(355.26, 238.6), 1, _blcName, reberBlockPath, 0, false);
                            else if (typeName == "BPTE3")
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -2).Convert3D(355.26, 249.1), 1, _blcName, reberBlockPath, 0, false);
                            else
                                BlockTool.InsertBlockReference(Point2d.Origin.Convert3D(420 * i, -297 * -2).Convert3D(355.26, 244), 1, _blcName, reberBlockPath, 0, false);
                        }

                    }
                }
                #endregion
            }
            catch
            {

            }
        }
        public static void DrawingMainCapBeamRebar(Database db, Point3d startPoint, double length, string typeName, string _dwgPath, double scale, ref List<Extents2d> exts, string columnNo = "")
        {
            string _blcName = "";
            Dictionary<string, Dictionary<string, string>> dicA = new Dictionary<string, Dictionary<string, string>>();
            Dictionary<string, string> dicT = new Dictionary<string, string>();
            string directoryName = System.IO.Path.GetDirectoryName(_dwgPath);
            string reberBlockPath = directoryName + @"\BeamReberBlock.dwg";//构造物
            if (typeName == "BPTM1" || typeName == "BPTM1S" || typeName == "BPTM2" || typeName == "BPTM2S" || typeName == "BPTM3S" )
            {
                #region 第一页
                Extents2d ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                if (length - 2 * 0.8 > 0)
                {
                    dicA = new Dictionary<string, Dictionary<string, string>>();
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length - 2 * 0.8).ToString("0.000"), "string");
                    dicA.Add("TWIDTH", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                    dicA.Add("LEFTWIDTH1", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                    dicA.Add("RIGHTWIDTH1", dicT);
                    dicT = new Dictionary<string, string>();
                    dicT.Add((length - 2 * 0.8).ToString("0.000"), "string");
                    dicA.Add("TWIDTH1", dicT);
                    if (typeName != "BPTM2S")
                    {
                        dicT = new Dictionary<string, string>();
                        dicT.Add((length * 0.5).ToString("0.000"), "string");
                        dicA.Add("TBMIDWIDTH", dicT);
                        dicT = new Dictionary<string, string>();
                        dicT.Add((length * 0.5).ToString("0.000"), "string");
                        dicA.Add("TBMIDWIDTH1", dicT);
                    }
                    _blcName = typeName.Replace("B", "") + "-Y";
                    if (typeName == "BPTM3S")
                    {
                        _blcName = typeName.Replace("B", "") + "-1Y";
                    }
                   

                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(0, -2), scale, _blcName, reberBlockPath, dicA, null, ref ext);

                }
                exts.Add(ext);
                #endregion

                #region 第二页
                //startPoint = startPoint.Convert3D(420);
                dicA = new Dictionary<string, Dictionary<string, string>>();

                if (typeName == "BPTM3S")
                {
                    startPoint = startPoint.Convert3D(420, -297+75);
                    ext = new Extents2d(startPoint.Convert2D(0,-5), startPoint.Convert2D(0, -5));
                    if (length - 2 * 0.8 > 0)
                    {
                        _blcName = typeName.Replace("B", "") + "-2Y1";
                        db.CopyBlockFromFile(reberBlockPath, _blcName);
                        BlockTool.InsertBlockReference(startPoint.Convert3D(), 66.6666, _blcName, reberBlockPath, null, null, ref ext);
                        double width = ext.W() + 15;
                        _blcName = typeName.Replace("B", "") + "-2Y2";
                        db.CopyBlockFromFile(reberBlockPath, _blcName);
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width), 66.6666, _blcName, reberBlockPath, null, null, ref ext);
                        double height = ext.L() + 10;
                        width = ext.W();
                        dicT = new Dictionary<string, string>();
                        dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                        dicA.Add("LEFTWIDTH", dicT);
                        dicT = new Dictionary<string, string>();
                        dicT.Add(((length - 2 * 0.8) * 0.5).ToString("0.000"), "string");
                        dicA.Add("RIGHTWIDTH", dicT);
                        dicT = new Dictionary<string, string>();
                        dicT.Add((length - 2 * 0.8).ToString("0.000"), "string");
                        dicA.Add("TWIDTH", dicT);
                        dicT = new Dictionary<string, string>();
                        dicT.Add((length * 0.5).ToString("0.000"), "string");
                        dicA.Add("TBMIDWIDTH", dicT);
                        _blcName = typeName.Replace("B", "") + "-2Y";
                        db.CopyBlockFromFile(reberBlockPath, _blcName);
                        BlockTool.InsertBlockReference(startPoint.Convert3D(width * 0.5, height+115), scale, _blcName, reberBlockPath, dicA, null, ref ext);
                    }
                }
                else
                {
                    startPoint = startPoint.Convert3D(420, -297+20);
                    ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                    _blcName = typeName.Replace("B", "") + "-Y1";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(), 33.3333, _blcName, reberBlockPath, null, null, ref ext);
                    double width = ext.W() + 10;
                    _blcName = typeName.Replace("B", "") + "-Y2";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, 0), 6.6667, _blcName, reberBlockPath, null, null, ref ext);
                    double height = ext.L() + 3;
                    _blcName = typeName.Replace("B", "") + "-Y3";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(0, height), 20, _blcName, reberBlockPath, null, null, ref ext);
                    width = ext.W() + 3;
                    _blcName = typeName.Replace("B", "") + "-Y4";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, 118), 33.3333, _blcName, reberBlockPath, null, null, ref ext);
                    string Contents =
           "Notes:\\P" +           "1.All dimensions are in m unless otherwise indicated.\\P" +           "2.The contractor shall verify all dimensions on site and resolve all discrepancies with the engineer &architect before commencement of work.\\P" +           "3.All the produced unsuitable material shall be transport to the designate disposal area in a properly manner.\\P" +           "4.All the site activities and operations shall follow the requirement of the approved Health and Safety Management Plan strictly.\\P" +           "5.Concrete shall have the minimum 45MPa of cylinder compressive strength at 28 days.\\P" +           "6.Reinforcement steel shall have the minimum yield strength 500MPa.\\P" +           "7.Concrete cover shall be 0.050m for cross beam.\\P" +           "8.In case there is any constrain at the left end such as difficulty to access,tensioning can be performed by jacking from right end at the option of the contractor.\\P" +           "9.The void space between the duct and the tendon shall be filled with grout\\P" +
           "10.The scaffolding supported cross beam should be removed before stressing stage 1 only when concrete strength of cross beam has reached or exceed 36MPa(cylinder).\\P";

                    TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(width-40, 116), Contents, 1, 2.5, 125);
                }
                //TextPloter.PrintMultiText(db, ref ext, startPoint.Convert3D(-ext.W() * 0.5 + 15, -height), Contents, 1, 2.5, 250);
                exts.Add(ext);
                #endregion

                #region 第三页
                //startPoint = startPoint.Convert3D(420);
                if (typeName == "BPTM3S")
                {
                    startPoint = startPoint.Convert3D(420,0);
                    ext = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                    _blcName = typeName.Replace("B", "") + "-Y1";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(), 16.6667, _blcName, reberBlockPath, null, null, ref ext);
                    double width = ext.W() + 10;
                    _blcName = typeName.Replace("B", "") + "-Y2";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, 0), 16.6667, _blcName, reberBlockPath, null, null, ref ext);
                    width = ext.W() + 10;
                    _blcName = typeName.Replace("B", "") + "-Y3";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, 0), 16.6667, _blcName, reberBlockPath, null, null, ref ext);
                    double height = ext.L() + 10;
                    Extents2d ext1 = new Extents2d(startPoint.Convert2D(), startPoint.Convert2D());
                    _blcName = typeName.Replace("B", "") + "-Y4";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(0, height), 35, _blcName, reberBlockPath, null, null, ref ext1);
                    width = ext1.W() + 10;
                    _blcName = typeName.Replace("B", "") + "-Y5";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 33.3333, _blcName, reberBlockPath, null, null, ref ext1);
                    width = ext1.W() + 10;
                    _blcName = typeName.Replace("B", "") + "-Y6";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, height), 33.3333, _blcName, reberBlockPath, null, null, ref ext1);
                    ext = ext.Add(ext1);
                    width = ext.W() + 10;
                    _blcName = typeName.Replace("B", "") + "-Y7";
                    db.CopyBlockFromFile(reberBlockPath, _blcName);
                    BlockTool.InsertBlockReference(startPoint.Convert3D(width, 50), 20, _blcName, reberBlockPath, null, null, ref ext);
                    exts.Add(ext);
                }
               
                #endregion
            }

        }

        //static double tbH = 0;
        public static Table DrawBeamTable(Database db, ref Extents2d ext, Point3d startPoint,
 string txtStyle, double scale, TendonCollection tbValue, string pierName,ref System.Data.DataTable dt, ref Dictionary<string, System.Data.DataTable> dicP , int pageCount = 0,string title= "MAINLINE",bool isLeft=false)
        {
            System.Data.DataTable dtP = dt.Clone();
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Stressing\\PStage");
            headName.Add("Tendon NO.");
            headName.Add("Tendon Size");
            headName.Add("Jacking Force\\P(KN)");
            headName.Add("Length\\P(m)");
            headName.Add("Unit Weight\\P(kg)");
            headName.Add("Total Weight\\P(kg)");
            headName.Add("Stressing End");
            headName.Add("Min. Concrete Cylinder\\PStrength at Transfer\\P(Mpa)");
            headName.Add("Stressing-End\\PAnchorage Type");
            headName.Add("Dead-End\\PAnchorage Type");
            headName.Add("Length of Duct\\P(m)");
            headName.Add("Elongation\\P(m)");
            //headName.Add("Degres\\P(m)");
            //tbH = 0;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                int rowNum = tbValue.Count + 2;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("INFORMATION SHEET OF CROSS BEAM FOR {0} {1}", pierName, title);
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 6.5 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 15 * scale;

                int numS1 = 0, numS2 = 0;
                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    int num = dt.Rows.Count;
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        num++;
                        try
                        {
                            System.Data.DataRow dr = dt.NewRow();
                            System.Data.DataRow drP = dtP.NewRow();
                            dr[0] = num;
                            dr[1] = pierName;
                            dr[2]= "T" + tbValue[m].MTendonMark.ToString();
                            Dictionary<string, double> dic = tbValue[m].ReportLine;
                            dr[3] = dic["曲线长度"];
                            dr[4] = dic["平直段长度"];
                            dr[5] = dic["理论长度"];
                            dr[6] = dic["张拉端B值"];
                            dr[7] = dic["限位环厚度"];
                            dr[8] = dic["P锚B值"];
                            dr[9] = dic["管道长度"];
                            dr[10] = dic["张拉端工作长度"];
                            dr[11] = dic["张拉端预留长度"];
                            dr[12] = dic["限位块厚度"];
                            dr[13] = dic["锚头总厚度"];
                            dr[14] = dic["固定端预留长度"];
                            dr[15] = dic["钢绞线下料长度"];
                            dr[16] = dic["张拉应力"];
                            dr[17] = dic["伸长量"];
                            dr[18] = dic["角度值"]; 

                            dt.Rows.Add(dr);
                            drP[0] = num;
                            drP[1] = pierName;
                            drP[2] = "T" + tbValue[m].MTendonMark.ToString();
                    
                            drP[3] = dic["曲线长度"];
                            drP[4] = dic["平直段长度"];
                            drP[5] = dic["理论长度"];
                            drP[6] = dic["张拉端B值"];
                            drP[7] = dic["限位环厚度"];
                            drP[8] = dic["P锚B值"];
                            drP[9] = dic["管道长度"];
                            drP[10] = dic["张拉端工作长度"];
                            drP[11] = dic["张拉端预留长度"];
                            drP[12] = dic["限位块厚度"];
                            drP[13] = dic["锚头总厚度"];
                            drP[14] = dic["固定端预留长度"];
                            drP[15] = dic["钢绞线下料长度"];
                            drP[16] = dic["张拉应力"];
                            drP[17] = dic["伸长量"];
                            dr[18] = dic["角度值"];
                            dtP.Rows.Add(drP);
                            
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].StressStage.ToString();
                            if (value == "1")
                                numS1++;
                            else if (value == "2")
                                numS2++;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = "T" + tbValue[m].MTendonMark.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].StrandsNum + "-" + double.Parse(System.Text.RegularExpressions.Regex.Replace(tbValue[m].StrandsType.ToString(), @"[^0-9]+", "").ToString()) * 0.1 + "mm"; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;


                            n++;
                            value = "";
                            if (tbValue[m].JackingForce != 0)
                                value = tbValue[m].JackingForce.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                            {
                                value = tbValue[m].Length.ToString("0.000");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000");
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000");
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].StressType == eForceType.OneEnd)
                            {
                                if (isLeft)
                                    value = "Left end";
                                else
                                    value = "Right end";
                            }
                            else
                                value = "Both end";
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].StressStage == 1)
                                value = "36";
                            else
                                value = "45";
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].StrandsNum != 0)
                                value = "OVM.M15A-" + tbValue[m].StrandsNum.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].StrandsNum != 0)
                                value = "OVM.P15-" + tbValue[m].StrandsNum.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].DuctLength != 0)
                                value = tbValue[m].DuctLength.ToString("0.000");
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            n++;
                            value = "";
                            if (tbValue[m].Elongation != 0)
                                value = tbValue[m].Elongation.ToString("0.000");
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                        }
                        catch (Exception ex)
                        { }
                    }
                    dicP.Add(pierName, dtP);
                }
                tb.MergeCells(CellRange.Create(tb, 2, 0, 1 + numS1, 0));
                if(numS2!=0)
                tb.MergeCells(CellRange.Create(tb, 2 + numS1, 0, 1 + numS1 + numS2, 0));

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i < 8)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i == 8)
                        tb.Columns[i].Width = 12 * 3 * scale;
                    else
                        tb.Columns[i].Width = 9 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 6 * scale;
                }

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                Point2d pNote = pt2.Convert2D(0,2);
                //MText theNote = new MText();
                //theNote.Contents =
                //       "STRESSING STAGE 1:FOR SUPPORT CROSS BEAM SELFWEIGHT\\P" +
                //       "STRESSING STAGE 2:AFTER INSTALL I-GIRDER OF 1st AND 2nd SPAN AND BEFORE INSTALL DECK SLAB OF 1st AND 2nd SPAN\\P";

                //theNote.Location = pNote.Convert3D();
                //theNote.TextStyleId = st[txtStyle];
                //theNote.TextHeight = 3.5;
                //theNote.Width = 140;
                //modelSpace.AppendEntity(theNote);
                //tr.AddNewlyCreatedDBObject(theNote, true);
                //tr.Commit();
                //string Contents =
                //       "STRESSING STAGE 1:FOR SUPPORT CROSS BEAM SELFWEIGHT\\P" +
                //       "STRESSING STAGE 2:AFTER INSTALL I-GIRDER/T-GIRDER OF 1st AND 2nd SPAN\\P";
                string Contents =
                      "Stressing stage 1:for support cross beam selfweight.\\P" +
                      "Stressing stage 2:after install i-girder/T-girder of 1st and 2nd span.";
                TextPloter.PrintMultiText(db, ref ext, pNote.Convert3D(), Contents, 1, 2.5, tb.Width);
                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }
    }
}
